package thread.synchronize_base;

/**
 * Created by mHandler on 2018/5/28 0028.
 * Description:
 *
 */
public class GoodCase extends Thread {
    public  int num = 0;
    private String name;
    public GoodCase(String name){
        this.name = name;
    }
    @Override
    public void run() {
        super.run();
        addNum(this.name);
    }

    synchronized public void addNum(String name){
        try {
            if (name.equals("a")){
                num = 100;
                System.out.println("a set over");
                Thread.sleep(1000);
            }else {
                num = 200;
                System.out.println("b set over");
            }
            System.out.println(name + "=" + num);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        GoodCase caseA = new GoodCase("a");
        caseA.start();
//        try{
//            Thread.sleep(2000);
//        }catch (Exception e){
//            e.printStackTrace();
//        }
        GoodCase caseB = new GoodCase("b");
        caseB.start();
    }
}
